// pages/index/component/advertisement/advertisement.js
import {
  list
} from '../../../../api/ad'
const util = require('../../../../utils/util')
let app = getApp();
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    info: {
      type: Object,
    }
  },
  lifetimes: {
    attached() {
      var arr = Object.keys(this.data.info.tagids)
      if (arr.length > 0) {
        this.data.tagIds = this.data.info.tagids.split(',')
        console.log(this.data.tagIds)
        for (var i = 0; i < this.data.tagIds.length; i++) {
          this.data.tagIds[i] = parseInt(this.data.tagIds[i])
        }
        this.setData({
          tagIds: this.data.tagIds
        })
      }
      this.loadAd()
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    adList: [],
    tagIds: [],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    toLink(data) {
      console.info("点击到我了")
        console.info(data)
      if (data.currentTarget.dataset.type == 0) {
        wx.navigateTo({
          url: '/pages/shop/productDetail/productDetail?productId=' + data.currentTarget.dataset.id
        })
      } else if (data.currentTarget.dataset.type == 2) {
        wx.navigateTo({
          url: '/pages/hotspot/hotspot/index?id=' + data.currentTarget.dataset.id,
        })
      } else if (data.currentTarget.dataset.type == 3) {
        wx.navigateTo({
          url: '/pages/discovery/details/details?id=' + data.currentTarget.dataset.id
        })
      } else if (data.currentTarget.dataset.type == 4) {
        wx.navigateTo({
          url: '/pages/travel/travel/index?scenicSpotId=' + data.currentTarget.dataset.id
        })
      } else if (data.currentTarget.dataset.type == 5) {
        wx.navigateTo({
          url: '/pages/shop/shopDetail/index?shopId=' + data.currentTarget.dataset.id + '&mchId=' + app.globalData.mchId
        })
      } else if (data.currentTarget.dataset.type == 6) {
        wx.navigateTo({
          url: '/pages/cook/kitchenBrigade/kitchenBrigade?id=' + data.currentTarget.dataset.id + '&mchId=' + app.globalData.mchId
        })
      } else if (data.currentTarget.dataset.type == 7) {
        wx.navigateTo({
          url: '/pages/shop/shopDetail/index?shopId=' + data.currentTarget.dataset.id + '&mchId=' + app.globalData.mchId
        })
      } else if (data.currentTarget.dataset.type == 8) {
        wx.navigateTo({
          url: '/pages/coupon/coupon',
        })
      } else if (data.currentTarget.dataset.type == 9) {
        wx.navigateTo({
          url: '/pages/index/wxPage/wxPage?id='+data.currentTarget.dataset.id 
        })
      }else if (data.currentTarget.dataset.type == 12) {
        console.info("点击到我了12*******")
        console.info(data.currentTarget.dataset.adlist.typeName)
        if(data.currentTarget.dataset.adlist.typeName!=""){
          wx.navigateTo({
            url: '/pages/member/webview/index?url='+data.currentTarget.dataset.adlist.typeName
          })
        }
        
      }
    },
    loadAd() {
      list({
        tagIds: this.data.tagIds,
        mchId: app.globalData.mchId,
      }).then(res => {
        this.data.adList = res.data.data
        this.setData({
          adList: this.data.adList
        })
      })
    }
  }
})